<template>
  <div class="receive_number">
    <Table :columns="columns"
           :loading="isLoading"
           stripe
           class="table-list"
           :data="data"></Table>
    <div class="page-box">
      <Page :total="size"
            :current="dataParmas.offset"
            :page-size="dataParmas.limit"
            @on-page-size-change="selectPageNum"
            @on-change="selectPageInde"
            ref="pages"
            show-total
            show-sizer />
    </div>
  </div>
</template>
<script>
import { shopStockReceive } from '@/api/report/shop'
import { formatDate } from '@/libs/tools'
export default {
  name: 'report_shop_gamecurrency_receive_number',
  data () {
    return {
      columns: [
        {
          title: '时间',
          key: 'dateCreated'
        },
        {
          title: '名称',
          key: 'cashierName'
        },
        {
          title: '数量',
          key: 'actualQuantity'
        },
        {
          title: '经手人',
          key: 'creatorName'
        }
      ],
      isLoading: true,
      size: 10,
      total: 0,
      dataArr: [], // 接口原始数据
      dataParmas: {
        offset: 1,
        limit: 10,
        shopId: [],
        startDate: '',
        endDate: '',
        cashierType: '',
        cashierId: ''
      },
      data: []
    }
  },
  mounted () {
    let objData = JSON.parse(localStorage.getItem('receiveNumber'))
    this.dataParmas.startDate = formatDate(new Date(new Date(objData.dayTimes).getTime()), 'yyyy-MM-dd') + ' 00:00:00'
    this.dataParmas.endDate = formatDate(new Date(new Date(objData.dayTimes).getTime() + 86400000), 'yyyy-MM-dd') + ' 00:00:00'
    this.dataParmas.shopId = objData.id
    this.dataParmas.cashierType = this.$route.params.id
    this.dataParmas.cashierId = objData.cashierId
    this.getStockReceive()
  },
  methods: {
    // 选择每页条数
    selectPageNum (num) {
      this.dataParmas.limit = num
      this.getStockReceive()
    },
    // 选择页面
    selectPageInde (pageIndex) {
      this.dataParmas.offset = pageIndex
      this.getStockReceive()
    },
    // 处理数据合计的
    processingDataTotal () {

    },
    // 获取领用数
    getStockReceive () {
      this.total = 0
      this.isLoading = true
      this.data = []
      shopStockReceive({
        merchantId: this.$store.state.user.merchantId,
        shopIds: this.dataParmas.shopId,
        startDate: this.dataParmas.startDate,
        endDate: this.dataParmas.endDate,
        offset: (this.dataParmas.offset - 1) * this.dataParmas.limit,
        limit: this.dataParmas.limit,
        cashierType: this.dataParmas.cashierType,
        cashierId: this.dataParmas.cashierId
      }).then(res => {
        if (res.data.status === 200) {
          this.dataArr = res.data.data
          this.isLoading = false
          if (res.data.data.length) {
            this.dataArr.forEach(ele => {
              this.total += ele.actualQuantity
            })
            this.dataArr.push({
              dateCreated: '合计',
              cashierName: '',
              actualQuantity: this.total,
              creatorName: ''
            })
            this.data = this.dataArr
            this.size = res.data.totalCount
          }
        } else {
          this.isLoading = false
          this.$Message.error(`${res.data.error}`)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.receive_number {
  padding-top: 80px;
  .table-total-list {
    border-top: none;
  }
}
</style>
